package com.spoplar.test;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.TextMessage;


public class QueueProductor {
	
	
	public static final String USER =  ActiveMQConnection.DEFAULT_USER;
	public static final String PASSWORD =  ActiveMQConnection.DEFAULT_PASSWORD;
	public static final String BROKER_URL =  ActiveMQConnection.DEFAULT_BROKER_URL;
	
	
	
	public static void main(String[] args) throws JMSException {
		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(USER,PASSWORD,BROKER_URL);
		
		Connection connection = connectionFactory.createConnection();
		connection.start();
		Session session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
		Destination destination = session.createQueue("hello");
		MessageProducer producer =  session.createProducer(destination);
		
//		TextMessage txMessage = session.createTextMessage("helloworld");
//		producer.send(txMessage);
		
		sendMsg(session,producer);
		
		session.commit();
		
		producer.close();
		session.close();
		connection.close();
		
	}



	private static void sendMsg(Session session, MessageProducer producer) throws JMSException {
		 for(int i=0;i<1;i++){
			    //Email email = new Email("1@qq.com","2@qq.com","123","333","444");
			    Sms sms = new Sms("13525522513","您的验证码是112233,请注意保密");
			    ObjectMessage objectMessage = session.createObjectMessage(sms);
			    producer.send(objectMessage);
			 //TextMessage textMessage = session.createTextMessage("hello"+String.valueOf(i));
			 //producer.send(textMessage);
		 }
	}

}
